import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'

// 自动导入vue中hook reactive ref等
import AutoImport from "unplugin-auto-import/vite";
//自动导入ui-组件 比如说ant-design-vue  element-plus等
import Components from 'unplugin-vue-components/vite';
// import { ElementPlusResolver } from "unplugin-vue-components/resolvers";
// import Icons from "unplugin-icons/vite";
// import IconsResolver from "unplugin-icons/resolver";

// import { createSvgIconsPlugin } from "vite-plugin-svg-icons";
// import mockDevServerPlugin from "vite-plugin-mock-dev-server";

import path from 'path';

export default defineConfig({
    resolve:{
        //使用@路径
        alias:{
          "@": path.resolve("./src")
        }
    },
    css: {
        // CSS 预处理器
        preprocessorOptions: {
            // 定义全局 SCSS 变量
            scss: {
                additionalData: `@use "./src/styles/public.scss" as *;`,
            },
        },
    },
    server:{
        // 允许IP访问
        host: "0.0.0.0",
        // 应用端口 (默认:3000)
        port: 4444,
        // 运行是否自动打开浏览器
        open: false,
        // 代理
        proxy: {
            "/api":{
                changeOrigin: true,
                // target: 'http://192.168.1.15:20131', //新-测试环境
                target: 'http://47.119.184.120:20131', //旧-测试环境
                rewrite: (path) => path.replace(new RegExp("^" + "/api"), ""),
                // pathRewrite: {
                //   '^/api': '/'
                // }
            }
        }
    },

    plugins:[
        vue(),
        AutoImport({
            imports: ["vue", "pinia", "vue-router"],
        }),
        
        Components({

        })
    ],

    // 预加载项目必需的组件
    optimizeDeps: {
        include:[
            "vue",
            "vue-router",
        ]
    }
})
